package com.yes_iot.controller;

import com.yes_iot.entity.LargeScreenConfiguration;
import com.yes_iot.entity.LargeScreenMoudle;
import com.yes_iot.entity.VisualMoudle;
import com.yes_iot.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/yesiot")
@Slf4j
@CrossOrigin
public class LargeScreenMoudleController extends BaseController{

    @RequestMapping(value = "/largeScreenMoudle/save", method = RequestMethod.POST)
    public Result save(@RequestBody LargeScreenMoudle largeScreenMoudle) {
        try {
            UUID id = largeScreenMoudle.getId();
            if (id==null){
                largeScreenMoudle.setId(UUID.randomUUID());
                largeScreenMoudle.setCreatedTime(System.currentTimeMillis());
            }
            return Result.succeed(largeScreenMoudleService.save(largeScreenMoudle),"保存成功");
        } catch (Exception e) {
            e.getMessage();
            return Result.failed(e.getMessage());
        }
    }

    @RequestMapping(value = "/largeScreenMoudle/{id}", method = RequestMethod.DELETE)
    public Result delete(@PathVariable String id) {
        try {
            largeScreenMoudleService.deleteById(id);
            return Result.succeed("删除成功");
        } catch (Exception e) {
            e.getMessage();
            return Result.failed(e.getMessage());
        }
    }
    @RequestMapping(value = "/largeScreenMoudle/{largeScreenConfigurationId}", method = RequestMethod.GET)
    public Result getByUserId(@PathVariable String largeScreenConfigurationId)  {
        try {
            List<LargeScreenMoudle> LargeScreenMoudleList =largeScreenMoudleService.findByLargeScreenConfigurationId(UUID.fromString(largeScreenConfigurationId));
            return Result.succeed(LargeScreenMoudleList,"查询成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.failed(e.getMessage());
        }
    }
}
